<?php session_start(); ?>
<div id="twistTopS" class="topShadow"></div>
	<div class="invitePage">
		<h3 style="border-bottom: #CCC 1px solid; margin-bottom: 15px;">Invite friends using</h3>
		<div class="w-invite" style="margin-bottom: 40px;">
			<h5>Email:</h5>
			<form>
				<div class="regFrmItem" style="float: left; width: 282px;">
					<input id="invite-email-field" name="email" class="regInputItem ghost_text" placeholder="william@gmail.com" type="text" />
					<div id="invite-email-error" class="hide clear rError">
						<div id="i-e-invalid" class="errorMsg hide rError" style="border-radius: 0 0 3px 3px; padding: 5px;">Please provide a valid email.</div>
						<div id="i-e-fail" class="errorMsg hide rError" style="border-radius: 0 0 3px 3px; padding: 5px;">Unable to send invite. Please try again later.</div>
						<div id="i-e-success" class="hide rError successMsg" style="margin-top: -3px;">Your friend has been successfully invited!</div>
					</div>
				</div>
				<button id="email-invite" type="button" class="btnB" style="margin-top: 10px; margin-left: 10px;">Send Invite</button>
			</form>
		</div>
		<div class="w-invite"  style="margin-bottom: 30px;">
			<h5>Your contacts:</h5>
			<ul class="o-invite">
				<li>
					<a href='https://accounts.google.com/o/oauth2/auth?client_id=908764803703.apps.googleusercontent.com&redirect_uri=<?php echo DOMAIN; ?>/oauth/oauth.php&scope=https://www.google.com/m8/feeds/&response_type=code'>
						<img src="<?php echo DOMAIN; ?>/img/gmail_logo_120X44.png" title="Gmail contacts" width="120" style="margin-bottom: 5px;"/>
						<p>Get Gmail Contacts</p>
					</a>
				</li>
			</ul>
		</div>
		<div class="clear"></div>
		<div class="invitee">
			<?php if(isset($_SESSION['result']) && $_SESSION['result']){ ?>
				<div class="n-invitee">
					<h5>Invite friends to Next Twist</h5>
					<ul class="invitee-list">
						<?php
							$count = 0;
							foreach ($_SESSION['contacts'] as $email) {
								if(strlen($email) < 50){
									//If email already registered, skip email and instead display follow link
									if(isEmailAvailable($email)) {
										if(isEmailInvited($email, $_SESSION['userId'])){
											echo "<li>{$email}<span class='btnG invite-btn' data-email='{$email}'>Invited</span></li>";
										} else {
											echo "<li>{$email}<span class='btnB email-invite-btn invite-btn' data-email='{$email}'>Invite</span></li>";
										}
										$count++;
									}
								}
							}
							
							if($count == 0){
								echo "<li class='blank'>You have no contacts</li>";
							}
						?>
					</ul>
				</div>
				<div class="a-invitee" style="margin-right: 0;">
					<h5>Follow friends who are already in Next Twist</h5>
					<ul class="invitee-list">
						<?php
							$count = 0;
							foreach ($_SESSION['contacts'] as $email) {
								if(strlen($email) < 50){
									$cur_email = getEmail($_SESSION['userId']);
									//If email already registered, skip email and instead display follow link
									if(!isEmailAvailable($email) && ($cur_email != $email)) {
										$frenId = getUserId($email);
										$name = getName($frenId);
										if(isFriend($frenId, $_SESSION['userId'])){
											echo "<li><p><a href='".DOMAIN."/{$name}'>{$name}</a></p><p style='font-size: 10px; color: #777;'>{$email}<p><span class='btnG follow-btn' data-fid='{$frenId}'>Following</span></li>";
										} else {
											echo "<li><p><a href='".DOMAIN."/{$name}'>{$name}</a></p><p style='font-size: 10px; color: #777;'>{$email}<p><span class='btnLb email-follow-btn follow-btn' data-fid='{$frenId}'>Follow</span></li>";
										}
										$count++;
									}
								}
							}
							if($count == 0){
								echo "<li class='blank'>You have no friends registered.</li>";
							}
						?>
					</ul>
				</div>
			<?php } elseif(isset($_SESSION['result']) && !$_SESSION['result']) { ?>
				<div class="error-invitee">Unable to retrieve Gmail contacts. Please try again later.</div>
			<?php } ?>
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
<div id="twistBottomS" class="bottomShadow"></div>